package com.linewell.demo.Signature;

import java.io.*;

public class IOUtils {


	public static void closeStream(OutputStream os){
		try {
			if(os!=null){
				os.close();
			}
		} catch (IOException e) {
//			logger.warn("IO流关闭异常", e);
		}
	}

	public static void closeStream(InputStream is){
		try {
			if(is!=null){
				is.close();
			}
		} catch (IOException e) {
//			logger.warn("IO流关闭异常", e);
		}
	}

	/**
     * 输入流转byte[]
	 * @param inputStream
     * @return
     * @throws IOException
	 */
    public static byte[] inputStreamToByte(InputStream inputStream) throws IOException {
		String pk;
		Reader reader =  new InputStreamReader(inputStream);
		StringWriter writer = new StringWriter();
		io(reader,writer);
		pk = writer.toString();
		inputStream.close();
		reader.close();
		writer.close();
		return pk.getBytes();
	}

	public static void io(Reader reader,Writer writer) throws IOException {
		char[] buffer = new char[4096];
		int amount;
		while ((amount = reader.read(buffer)) >= 0) {
			writer.write(buffer, 0, amount);
		}
	}
}
